@extends('../manage.layout')
@section('link')
    <!-- Date Picker -->
    <link rel="stylesheet" href="/plugin/AdminLTE-2.3.11/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/plugin/AdminLTE-2.3.11/plugins/daterangepicker/daterangepicker.css">
    <style>
        .h {
            height: 30px;
            margin-right: -4px;
        }
        .st {
            border: 1px solid #d2d6de;
            padding-left: 8px;
        }
    </style>
@endsection
@section('content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            服务理念管理
            <small>服务理念列表</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/manage"><i class="fa fa-dashboard"></i>首页</a></li>
            <li class="active">服务理念列表</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content animated fadeInRight">
        <div class="row">
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <form action="/manage/idea" method="get" >
                            @include('manage.search')
                        </form>
                    </div>
                    <!-- table start -->
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">服务理念信息</h3>
                                </div>
                                <!-- /.box-header -->
                                <div class="box-body table-responsive no-padding">
                                    <table class="table table-bordered table-hover table-striped">
                                        <tr>
                                            @foreach($field as $d => $f)
                                                <th title="{{ $d }}" onclick="order(this)" style="cursor: pointer">{{ $f }}<i id="{{ $d }}" class="fa fa-sort"></i></th>
                                            @endforeach
                                            <th>操作</th>
                                        </tr>
                                        @foreach($data as $k => $value)
                                            <tr>
                                                <td>{{ $value['id'] }}</td>
                                                <td>{{ $value['create_time'] }}</td>
                                                <td>{{ $value['update_time'] }}</td>
                                                <td title="{{ $value['create_user'] }}">{{ App\Model\Manage::find($value['create_user'])['username'] }}</td>
                                                <td title="{{ $value['update_user'] }}">{{ App\Model\Manage::find($value['update_user'])['username'] }}</td>
                                                <td>{{ $value['rank'] }}</td>
                                                <td>{{ $value['title'] }}</td>
                                                <td>{{ $value['keywords'] }}</td>
                                                <td>
                                                    @if($value['status'] == 0)<span class="label label-warning">已禁用</span>
                                                    @else<span class="label label-success">已启用</span>
                                                    @endif
                                                </td>
                                                <td>
                                                    <a href="idea/{{ $value['id'] }}/edit"><span class="btn btn-primary btn-xs">更改</span></a>
                                                    @if($value['status'] == 1)
                                                        <a class="btn btn-warning btn-xs" href="javascript:status('{{ $value['id'] }}',0)">禁用<a>
                                                    @elseif($value['status'] == 0)
                                                        <a class="btn btn-success btn-xs" href="javascript:status('{{ $value['id'] }}',1)">启用<a>
                                                    @endif
                                                    <a href="javascript:delSubscribe({{ $value['id'] }})"><span class="btn btn-danger btn-xs">删除</span></a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    </table>
                                    <div id="type" style="display: none">{{ $type }}</div>
                                    <div id="code" style="display: none">{{ $code }}</div>
                                </div>
                                <!-- /.box-body -->
                                <div class="box-footer">
                                    <div style="text-align: center">{{ $data->appends(['check_time'=>$check_time,'category'=>$category,'create_time'=>$time,'keyword'=>$keyword,'type'=>$type,'code'=>$code])->links() }}</div>
                                </div>
                            </div>
                            <!-- /.box -->
                        </div>
                    </div>
                    <!-- /.table -->
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
@endsection
@section('script')
    <!-- daterangepicker -->
    <script src="/plugin/AdminLTE-2.3.11/thirdparty/js/moment.min.js"></script>
    <script src="/plugin/AdminLTE-2.3.11/plugins/daterangepicker/daterangepicker.js"></script>
    <!-- datepicker -->
    <script src="/plugin/AdminLTE-2.3.11/plugins/datepicker/bootstrap-datepicker.js"></script>
    <!--layer-->
    <script src="/plugin/layer-v3.0.3/layer/layer.js"></script>
    <script src="/js/manage/date_range.js"></script>
    <script>
        for(var i=0;i<'{{count($data)}}';i++){
            layer.photos({
                photos: "#md-"+i
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
        }

        function delSubscribe(id) {
            layer.confirm('删除后不可恢复，是否继续?', {
                btn:['确定','取消']
            },function() {
                $.ajax({
                    url: '/manage/idea/delete',
                    type: "GET",
                    data: {id:id},
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
//                            window.location.href = "/manage/article";
                            layer.msg(res.msg, {time:1500, end:function(){location.reload();}})
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        }

        //禁用,启用
        function status(id,status) {
            console.log(id);
            $.ajax({
                url: '/manage/idea/status',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5})
                    }
                },
                error:function(){
                    alert('ERROR');
                }
            });
        }

        //获取排序状态，改变图标
        $(function(){
            var c = $('#code').text();
            var t = $('#type').text();
            if(c == 0) {
                $('#'+t).attr("class", "fa fa-sort-asc");
            }
            if(c == 1) {
                $('#'+t).attr("class", "fa fa-sort-desc");
            }
        });

        //排序
        function order(node) {
            var type = null;
            var str = $(node).children().attr('class');
            if(str.indexOf('asc')!=-1) {
                data = {type:node.title,code:1};
                console.log(data);
                window.location.href = '/manage/idea?type='+node.title+'&code=1';
            }
            else {
                data = {type:node.title,code:0};
                console.log(data);
                window.location.href = '/manage/idea?type='+node.title+'&code=0';
            }

        }
    </script>
@endsection

